/** @author Michael Floyd
 * @date March 9, 2007
 */
package rcscene;

import java.io.Serializable;

/** This class is used to store the weights that
 * will be used for each action type. This class
 * was created in order to more appropriately
 * store the weight data and to avoid the use
 * of an array.
 * 
 */
public class ActionWeights implements Serializable {


	private static final long serialVersionUID = 1L;
	
	private float NONEWeight;
	private float DASHWeight;
	private float KICKWeight;
	private float TURNNECKWeight;
	private float TURNWeight;
	private float CATCHWeight;
	private float MOVEWeight;
	
	private int NUM_WEIGHTS = 7;
	private float WEIGHT_MIN = 0;
	private float WEIGHT_MAX = 1;

	
	/** Given an array of doubles (with a size equal to the number
	 *  of weights, NUM_WEIGHTS ), the weights will be set to the
	 *  values specified in the array. Currently, there are 7 weights
	 *  used. The weights will be assigned in the following order :
	 *  NONE, DASH, KICK, TURNNECK, TURN, CATCH, MOVE.
	 *  So weights[0] will be assigned to the NONEWeight, and weight[6] will
	 *  be assigned to the MOVEWeight.
	 * 
	 */
	public ActionWeights(float[] weights){
		if(weights.length != NUM_WEIGHTS){
			throw new IllegalArgumentException("Invalid number of object weights " +
					"supplied. Expecting " + NUM_WEIGHTS + " given " + weights.length);
		}
		
		verifyRange(WEIGHT_MIN,WEIGHT_MAX,weights[0]);
		this.NONEWeight = weights[0];
		verifyRange(WEIGHT_MIN,WEIGHT_MAX,weights[1]);
		this.DASHWeight = weights[1];
		verifyRange(WEIGHT_MIN,WEIGHT_MAX,weights[2]);
		this.KICKWeight = weights[2];
		verifyRange(WEIGHT_MIN,WEIGHT_MAX,weights[3]);
		this.TURNNECKWeight = weights[3];
		verifyRange(WEIGHT_MIN,WEIGHT_MAX,weights[4]);
		this.TURNWeight = weights[4];
		verifyRange(WEIGHT_MIN,WEIGHT_MAX,weights[5]);
		this.CATCHWeight = weights[5];
		verifyRange(WEIGHT_MIN,WEIGHT_MAX,weights[6]);
		this.MOVEWeight = weights[6];
		
	}
	
	/** Default constructor. All weights will be set to their
	 *  minimum value (usually 0 ).
	 * 
	 */
	public ActionWeights(){
		this.NONEWeight = WEIGHT_MIN;
		this.DASHWeight = WEIGHT_MIN;
		this.KICKWeight = WEIGHT_MIN;
		this.TURNNECKWeight = WEIGHT_MIN;
		this.TURNWeight = WEIGHT_MIN;
		this.CATCHWeight = WEIGHT_MIN;
		this.MOVEWeight = WEIGHT_MIN;
	}
	
	public float getCATCHWeight() {
		return CATCHWeight;
	}

	public void setCATCHWeight(float weight) {
		verifyRange(WEIGHT_MIN,WEIGHT_MAX,weight);
		CATCHWeight = weight;
	}

	public float getDASHWeight() {
		return DASHWeight;
	}

	public void setDASHWeight(float weight) {
		verifyRange(WEIGHT_MIN,WEIGHT_MAX,weight);
		DASHWeight = weight;
	}

	public float getKICKWeight() {
		return KICKWeight;
	}

	public void setKICKWeight(float weight) {
		verifyRange(WEIGHT_MIN,WEIGHT_MAX,weight);
		KICKWeight = weight;
	}

	public float getMOVEWeight() {
		return MOVEWeight;
	}

	public void setMOVEWeight(float weight) {
		verifyRange(WEIGHT_MIN,WEIGHT_MAX,weight);
		MOVEWeight = weight;
	}

	public float getNONEWeight() {
		return NONEWeight;
	}

	public void setNONEWeight(float weight) {
		verifyRange(WEIGHT_MIN,WEIGHT_MAX,weight);
		NONEWeight = weight;
	}

	public float getTURNNECKWeight() {
		return TURNNECKWeight;
	}

	public void setTURNNECKWeight(float weight) {
		verifyRange(WEIGHT_MIN,WEIGHT_MAX,weight);
		TURNNECKWeight = weight;
	}

	public float getTURNWeight() {
		return TURNWeight;
	}

	public void setTURNWeight(float weight) {
		verifyRange(WEIGHT_MIN,WEIGHT_MAX,weight);
		TURNWeight = weight;
	}

	public String toString(){
		return "[" + NONEWeight + "," + DASHWeight + "," + KICKWeight + "," + 
				TURNNECKWeight + "," + TURNWeight + "," + 
				CATCHWeight + "," + MOVEWeight + "]";
	}
	
	/** A method used by the weight setters to ensure the set weight
	 *  is within a specified range. 
	 *  @param min The minimum value of the weight
	 *  @param max The maximum value of the weight
	 *  @param value The weight that is being tested
	 *  @throws IllegalArgumentException If the weight is not
	 *  within the range.
	 */
	
	private void verifyRange(float min, float max, float value) 
										throws IllegalArgumentException{
		
		//ensure the minimum is less than the maximum
		if(min>max){
			float tmp = min;
			min = max;
			max = tmp;
		}
		if(value < min || value > max){
			throw new IllegalArgumentException("The weight must be " +
					"between " + min + " and " + max);
		}
	}
}

